// packageB/pages/shezhi/shezhi.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    appurl: app.apiurl,
    apiimg: app.apiimg,
    jietu: '',
    name:'',
    phone_type:'',
    yonghu:'',
    peizhi:'',
    array3: ['男', '女'],
    index3: 0,
    array5: ['安卓', 'IOS'],
    index5: 0,
    dw3: true,
    dw5: true,
    refereeid:"",
    xinhuiyuan:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.z_peizhi()
  },
  z_peizhi() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/configBase',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          peizhi: res.data.data
        })
      }
    })
  },
  bindPickerChange3: function (e) {
    let _this = this
    _this.setData({
      index3: e.detail.value,
      dw3: false
    })
  },
  bindPickerChange5: function (e) {
    let _this = this
    _this.setData({
      index5: e.detail.value,
      dw5: false
    })
  },
  z_nav1() {
    wx.navigateBack({
      delta: 1
    })
  },
  z_xiugai1() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
      "head_img": _this.data.jietu,
      "game_name": _this.data.name,
      "sex": _this.data.array3[_this.data.index3],
      "refereeid": _this.data.refereeid,
      "phone_type": Number(_this.data.index5) + 1,
      "is_new":'1'
    }
    if (_this.data.jietu == '') {
      wx.showToast({
        title: '请添加头像',
        icon: 'none',
        duration: 2000
      })
    } else if (_this.data.name == '') {
      wx.showToast({
        title: '请填写昵称',
        icon: 'none',
        duration: 2000
      })
    } else if (_this.data.dw3) {
      wx.showToast({
        title: '请选择性别',
        icon: 'none',
        duration: 2000
      })
    } else if(_this.data.dw5){
      wx.showToast({
        title: '选择您的手机系统',
        icon: 'none',
        duration: 2000
      })
    }  else {
      wx.request({
        url: app.apiurl + 'api/member/upGameLevel',
        method: 'POST',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
          if (res.data.code == '1001') {
             _this.setData({
               xinhuiyuan:true
             })
          } else {
            wx.showToast({
              title: res.data.msg,
              icon: 'none',
              duration: 2000
            })
          }
        }
      })
    }
  },
  z_shuru1(e) {
    this.setData({
      name: e.detail.value
    })
  },
  z_shuru2(e) {
    this.setData({
      refereeid: e.detail.value
    })
  },
  onChooseAvatar(e) {
    let that = this
    var tempFiles = e.detail.avatarUrl;
    wx.uploadFile({
      url: app.apiurl + 'api/common/upload',
      filePath: tempFiles,
      name: 'file',
      formData: {},
      success(res) {
        const data = JSON.parse(res.data)
        that.setData({
          jietu: data.data.fullurl
        })
      }
    })
  },
  z_xiugai2(){
        wx.reLaunch({
          url: '/pages/index/index',
        })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})